class Solution {
    public:
        int longestSubsequence(vector<int>& arr, int difference) {
            int n =arr.size();
            // vector<int> dp(n,1);
            unordered_map<int,int> hash;
            int ret = 1;
            hash[arr[0]] = 1;
            for(int i = 1 ; i < n ; i++){
                // for(int j = i-1; j >= 0 ; j--){
                //     if(arr[i] - arr[j] == difference){
                //         dp[i] = dp[j]+1;
                //         break;
                //     }
                // }
                hash[arr[i]] = hash[arr[i]-difference] + 1;
                ret = max(ret,hash[arr[i]]);
            }
            return ret;
        }
    };